import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:wch/native/net_business.dart';
import 'package:wch/widget/business_widget.dart';
import 'package:wch/widget/common_widget.dart';

import '../model/dcotor.dart';

class DoctorInfoPage extends StatefulWidget {
  const DoctorInfoPage({super.key, required this.id});

  final String id;

  @override
  State<DoctorInfoPage> createState() => _DoctorInfoPageState();
}

class _DoctorInfoPageState extends State<DoctorInfoPage> {

  DcotorModel model = DcotorModel();

  @override
  void initState() {
    NetBusiness().doctorInfo(widget.id).then((value) {
      // setState(() {
        model.data = value;
      // });
      model.notifyListeners();
    });
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider.value(
      value: model,
      child: Consumer<DcotorModel>(
        builder: (ctx, model, child){
          return CommonScaffold(title: '用户信息', body: Container(
            margin: EdgeInsets.only(top: 15.h),
            color: Color(0xFFF8F9FB),
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 15.w),
                  width: ScreenUtil().screenWidth-30.w,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(15.w)),
                  ),
                  child: Column(
                    children: [
                      CommonInputWidget.getShowWidget('用户名', _getName()),
                      LineWidget(width: ScreenUtil().screenWidth-70.w, height: 0.5),
                      CommonInputWidget.getShowWidget('手机号码', _getMobile()),
                      LineWidget(width: ScreenUtil().screenWidth-70.w, height: 0.5),
                      CommonInputWidget.getShowWidget('所在科室', _getDepartment()),
                      LineWidget(width: ScreenUtil().screenWidth-70.w, height: 0.5),
                      CommonInputWidget.getShowWidget('所属医院', _getHospital()),
                    ],
                  ),
                )
              ],
            ),
          ));
        },
      )
    );
  }

  String _getName() {
    if (model.data == null) {
      return '';
    }
    return model.data!.name ?? '';
  }
  String _getMobile() {
    if (model.data == null) {
      return '';
    }
    return model.data!.mobile ?? '';
  }
  String _getDepartment() {
    if (model.data == null) {
      return '';
    }
    return model.data!.department ?? '';
  }
  String _getHospital() {
    if (model.data == null) {
      return '';
    }
    return model.data!.hospital ?? '';
  }
}
